/**
 * @ProjectName:designPatern
 * @Title: FactoryMethodPattern
 * @Package _02factoryPattern
 * @Description: 工厂方法模式示例
 * @version V1.0
 * Copyright (c) 2025, 2034279227@qq.com All Rights Reserved.
 */

package _02factoryPattern;

/**
 * @author 梦无忧
 * @data 2025/6/4 20:28
 */
public class FactoryMethodPattern {
}

interface Phone{
    void product(); // 生产手机
    String getBrand(); // 获取品牌
}

class HuaweiPhone implements Phone{
    @Override
    public void product() {
        System.out.println("生产华为手机！");
    }

    @Override
    public String getBrand() {
        return "华为";
    }
}

class XiaoMiPhone implements Phone{
    @Override
    public void product() {
        System.out.println("生产小米手机！");
    }

    @Override
    public String getBrand() {
        return "小米";
    }
}

abstract class PhoneFactory{
    public abstract Phone createPhone();
    public void qualityInspection(Phone phone){
        System.out.println(phone.getBrand()+"手机质检！");
    }
}

class HuaweiFactory extends PhoneFactory{
    @Override
    public Phone createPhone() {
        return new HuaweiPhone();
    }
}

class XiaoMiFactory extends PhoneFactory{

    @Override
    public Phone createPhone() {
        return new XiaoMiPhone();
    }
}
